package fatworm.query.constant;

import fatworm.util.Lib;

public class TimeConstant implements Constant {
	
	private int year, month, day, hour, minute, second;
	private String origin;
	
	public TimeConstant(String val) {
		
		String[] list = val.split(" ");
		String[] s1 = list[0].split("-");
		year = Integer.parseInt(s1[0]);
		month = Integer.parseInt(s1[1]);
		day = Integer.parseInt(s1[2]);
		
		String[] s2 = list[1].split(":");
		hour = Integer.parseInt(s2[0]);
		minute = Integer.parseInt(s2[1]);
		second = Integer.parseInt(s2[2]);
		
		origin = val;
	}
	
	public Object asJavaVal() {
		return null;
	}
	
	public boolean equals(Object obj) {
		TimeConstant tc = (TimeConstant)obj;
		if (tc == null)
			return false;
		if (tc.year != year)
			return false;
		if (tc.month != month)
			return false;
		if (tc.day != day)
			return false;
		if (tc.hour != hour)
			return false;
		if (tc.minute != minute)
			return false;
		if (tc.second != second)
			return false;
		
		return true;
	}
	
	public int compareTo(Constant c) {
		TimeConstant tc = (TimeConstant)c;
		
		if (year > tc.year) 
			return 1;
		else if (year < tc.year)
			return -1;
		
		if (month > tc.month) 
			return 1;
		else if (month < tc.month)
			return -1;
		
		if (day > tc.day) 
			return 1;
		else if (day < tc.day)
			return -1;
		
		if (hour > tc.hour) 
			return 1;
		else if (hour < tc.hour)
			return -1;
		
		if (minute > tc.minute) 
			return 1;
		else if (minute < tc.minute)
			return -1;
		
		if (second > tc.second) 
			return 1;
		else if (second < tc.second)
			return -1;
		
		return 0;
	}
	
	public int hashCode() {
		return origin.hashCode();
	}
	
	public String toString() {
		return origin.toString();
	}
	
	public Constant plus(Constant c) {
		Lib.assertNotReached();
		return null;
	}
}